<template>
  <view class="container">

    <!-- 页面头部 -->
    <view class="header">
      <view class="title">
        <text>修改您的名称和密码</text>
      </view>
      <view class="sub-title">
        <text>经销商名称也是您的团队名称</text>
      </view>
    </view>
    <!-- 表单 -->
    <view class="submit-form">
		
		
		
      <!-- 经销商名称 -->
      <view class="form-item">
        <input class="form-item--input" type="text" v-model="real_name" maxlength="11" placeholder="请输入经销商名称" />
      </view>
		<view class="form-item">
		  <input class="form-item--input" type="password" v-model="password" placeholder="请输入需要更改的密码" />
		</view>

		<view class="form-item">
		  <input class="form-item--input" type="password" v-model="respassword" placeholder="再次输入密码" />
		</view>

      <!-- 确认绑定 -->
      <view class="submit-button" @click="onSubmitEvent()">
        <text>确认</text>
      </view>
    </view>

  </view>
</template>

<script>
  import store from '@/store'
  import * as UserApi from '@/api/user'

  export default {

    data() {
      return {
        real_name: '',//经销商名称
		password:'',
		respassword:'',
        type: '',//从那个页面过来的
      }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    created() {
    },
	onLoad(options) {
		if(options.real_name){
			this.real_name = options.real_name;
			this.type = options.type;
		}
	},

    methods: {

      // 确认提交事件
      onSubmitEvent() {
        const app = this
		
		if(!app.real_name){
			this.$toast('请先输入经销商名称')
			return false
		}
		if(app.respassword!=app.password){
			this.$toast('密码不一致')
			return false
		}
		
		
        UserApi.bindRealName({ form: { real_name: app.real_name,password:app.password } })
          .then(result => {
            // 显示操作成功
            app.$toast(result.message)
            // 跳转回原页面
            setTimeout(() => {
				this.$navTo('pages/'+ this.type +'/index',{},'redirectTo');
              // app.onNavigateBack(1)
            }, 2000)
          })
      },

      /**
       * 提交成功-跳转回原页面
       */
      onNavigateBack(delta) {
        uni.navigateBack({
          delta: Number(delta || 1)
        })
      }

    }
  }
</script>

<style lang="scss" scoped>
  .container {
    padding: 100rpx 60rpx;
    min-height: 100vh;
    background-color: #fff;
  }

  // 页面头部
  .header {
    margin-bottom: 50rpx;

    .title {
      color: #191919;
      font-size: 50rpx;
    }

    .sub-title {
      margin-top: 20rpx;
      color: #b3b3b3;
      font-size: 25rpx;
    }
  }

  // 输入框元素
  .form-item {
    display: flex;
    padding: 18rpx;
    border-bottom: 1rpx solid #f3f1f2;
    margin-bottom: 25rpx;
    height: 96rpx;

    &--input {
      font-size: 26rpx;
      letter-spacing: 1rpx;
      flex: 1;
      height: 100%;
    }

    &--parts {
      min-width: 100rpx;
      height: 100%;
    }

    // 图形验证码
    .captcha {
      height: 100%;

      .image {
        display: block;
        width: 192rpx;
        height: 100%;
      }
    }

    // 短信验证码
    .captcha-sms {
      font-size: 22rpx;
      line-height: 50rpx;
      padding-right: 20rpx;

      .activate {
        color: #cea26a;
      }

      .un-activate {
        color: #9e9e9e;
      }
    }
  }


  // 提交按钮
  .submit-button {
    width: 100%;
    height: 86rpx;
    margin-top: 70rpx;
    background: linear-gradient(to right, #ecb53c, #ff9211);
    color: #fff;
    border-radius: 80rpx;
    box-shadow: 0px 10px 20px 0px rgba(0, 0, 0, 0.1);
    letter-spacing: 5rpx;
    display: flex;
    justify-content: center;
    align-items: center;
  }
</style>
